#-*- coding: utf-8 -*-

from cocos.scene import Scene
from cocos.layer import ColorLayer,ScrollingManager,ScrollableLayer
from cocos.sprite import Sprite
from scene.map import CMap

class CScene(Scene):
	m_SID	=0
	m_Name	="None"
	m_Map 	=""

	def __init__(self):
		super(CScene,self).__init__()
		self.m_HUD=ColorLayer(50,0,0,255)
		self.m_Scroller=ScrollingManager()
		self.m_MainLayer=ScrollableLayer()
		self.m_Scroller.add(self.m_MainLayer,z=0)
		self.CreateMap()
		self.add(self.m_Scroller,z=0)
		self.OnCreate()
		self.schedule(self.Update)

	def CreateMap(self):
		if not self.m_Map:
			return
		sMap=self.m_Map
		oMap=CMap()
		oMap.Load(sMap)
		for sImg,zImg in oMap.m_Layers:
			layer=ScrollableLayer()
			spImg=Sprite(sImg,anchor=(0,0))
			layer.add(spImg)
			self.m_Scroller.add(layer,z=zImg)
		self.m_Map=oMap

	def EnterScene(self,obj):
		obj.m_Scene=self.m_SID
		self.m_MainLayer.add(obj,z=0)

	def LeaveScene(self,obj):
		pass

	def SetFocus(self,x,y):
		self.m_Scroller.set_focus(x,y)

	def ShowHUD(self):
		self.add(self.m_HUD,z=1)

	def HideHUD(self):
		self.m_HUD.kill()

	def on_enter(self):
		super(CScene,self).on_enter()
		print "enter Scene(%d)"%(self.m_SID)
		self.OnEnter()

	def on_exit(self):
		super(CScene,self).on_exit()
		print "enter Scene(%d)"%(self.m_SID)
		self.OnExit()

	def OnCreate(self):
		pass

	def OnEnter(self):
		pass

	def OnExit(self):
		pass

	def Update(self,dt):
		pass

Modules={}
import sc0001
import sc0002
Modules[1]=sc0001
Modules[2]=sc0002
